var gird;
window.onload = function(){
    grid = mini.get("datagrid1");

    //GridData_Page("datagrid1", "page", "/base/model/dataGrid.do", "", "&PID=-1");

    onPageChanged("");

    var tree1 = firstTree.sender;
    var node = tree1.getNode("-1");
    tree1.selectNode(node);



}

function onPageChanged(e) {
      var param = "";
      if(treeNode != null) {
          param = "&PID="+treeNode.node.id;
      }else {
          param = "&PID=-1";
      }
     GridData_Page("datagrid1", "page", "/base/model/dataGrid.do", e, param);
}


function onGenderRenderer(e) {
    if(e.field == "display") {
        if(e.value.equals("true"))  {
           return e.cellHtml = "<span class='icon-hok'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>";

        }else {
           return e.cellHtml = "<span class='icon-close'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>";
        }
    }
}

var num = 0;

//是否选中树对象
var treeNode = null;
//初次加载树对象
var firstTree = null;


function onBeforeTreeLoad(e) {
	var tree = e.sender; // 树控件
	var node = e.node; // 当前节点
	var params = e.params; // 参数对象
	// 可以传递自定义的属性
	// params.myField = "123"; //后台：request对象获取"myField"
    //onNodeClick(e);
    firstTree = e;
    //node.id = -1;
    //tree.selectNode(node);
}

function onNodeClick(e) {
    var node = e.node;
    var id = node.id;
    treeNode = e;
    onPageChanged("");
}

function onClick() {
    if(treeNode == null) {
        alert(1);
        return;
    }
    alert(treeNode.node.id);
}

/**
 * Add JSMethod
 */
function add() {
    var map = new HashMap();
    if(treeNode == null) {
        map.put("id", -1);
        map.put("name", "System");
    }else {
        map.put("id", treeNode.node.id);
        map.put("name", treeNode.node.name);
    }

    mini.open({
        url: "/psw/base/model/viewAdd.do",
        title: "New Model", width: 600, height:360,
        allowResize: false,
        onload: function () {
            var iframe = this.getIFrameEl();
            var data = { Map: map};
            iframe.contentWindow.SetData(data);
        },
        ondestroy: function (action) {
            //grid.reload();
            if(!"Cancel".equals(action)) {
                onPageChanged("");
                var tree1 = mini.get("tree1");
                tree1.loadNode(treeNode.node);
            }
        }
    });
}

function del() {

    var str = "<div style='background-color: red '></div>";

    alert(str);
    mini.alert(str);
}

/*Edit JSMethod*/
function edit() {
    var grid = mini.get("datagrid1");
    var row = grid.getSelected();

    if(row) {
        var map = new HashMap();
        if(treeNode == null) {
            map.put("id", row.id);
            map.put("pidName", "System");
        }else {
            map.put("id", row.id);
            map.put("pidName", treeNode.node.name);
        }

        var param = "ID="+row.id;


        mini.open({
            url: "/psw/base/model/viewEdit.do?"+param,
            title: "Edit Message", width: 600, height: 360,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { Map : map };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                if(!action.equals("cancel")) {
                    onPageChanged("");
                    var tree1 = mini.get("tree1");
                    tree1.loadNode(treeNode.node);
                }
                grid.deselectAll();
            }
        });
    }else {
        mini.alert("Please select GridRow.");
    }
}






